package com.ruoyi.web.controller.byManager;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ByCouponUser;
import com.ruoyi.system.service.IByCouponUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员优惠券Controller
 *
 * @author ruoyi
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/by/couponUser")
public class ByCouponUserController extends BaseController
{
    @Autowired
    private IByCouponUserService byCouponUserService;

    /**
     * 查询会员优惠券列表
     */
    @PreAuthorize("@ss.hasPermi('by:couponUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(ByCouponUser byCouponUser)
    {
        startPage();
        List<ByCouponUser> list = byCouponUserService.selectByCouponUserList(byCouponUser);
        return getDataTable(list);
    }

    /**
     * 导出会员优惠券列表
     */
    @PreAuthorize("@ss.hasPermi('by:couponUser:export')")
    @Log(title = "会员优惠券", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ByCouponUser byCouponUser)
    {
        List<ByCouponUser> list = byCouponUserService.selectByCouponUserList(byCouponUser);
        ExcelUtil<ByCouponUser> util = new ExcelUtil<ByCouponUser>(ByCouponUser.class);
        util.exportExcel(response, list, "会员优惠券数据");
    }

    /**
     * 获取会员优惠券详细信息
     */
    @PreAuthorize("@ss.hasPermi('by:couponUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(byCouponUserService.selectByCouponUserById(id));
    }

    /**
     * 新增会员优惠券
     */
    @PreAuthorize("@ss.hasPermi('by:couponUser:add')")
    @Log(title = "会员优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ByCouponUser byCouponUser)
    {
        return toAjax(byCouponUserService.insertByCouponUser(byCouponUser));
    }

    /**
     * 修改会员优惠券
     */
    @PreAuthorize("@ss.hasPermi('by:couponUser:edit')")
    @Log(title = "会员优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ByCouponUser byCouponUser)
    {
        return toAjax(byCouponUserService.updateByCouponUser(byCouponUser));
    }

    /**
     * 删除会员优惠券
     */
    @PreAuthorize("@ss.hasPermi('by:couponUser:remove')")
    @Log(title = "会员优惠券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(byCouponUserService.deleteByCouponUserByIds(ids));
    }
}
